import org.apache.flume.Context;
import org.apache.flume.Event;
import org.apache.flume.interceptor.Interceptor;

import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;


public class ETLClass implements Interceptor {
    @Override
    public void initialize() {

    }

    @Override
    public Event intercept(Event event) {
        byte[] body = event.getBody();
        String log = new String(body,Charset.forName("UTF-8"));

        if (log.contains("start")){
            if (LogUtils.validateEvent(log)){
                return event;
            }
        }else{
            if (LogUtils.validateEvent(log)){
                return event;
            }
        }
        return null;
    }

    @Override
    public List<Event> intercept(List<Event> list) {
        ArrayList<Event> list1 = new ArrayList<>();

        for (Event event : list) {
            Event intercept = intercept(event);

            if (intercept != null){
                list1.add(intercept);
            }
        }
        return list1;
    }

    @Override
    public void close() {

    }

    public static class Builder implements Interceptor.Builder{

        @Override
        public Interceptor build() {
            return new ETLClass();
        }

        @Override
        public void configure(Context context) {

        }
    }
}
